package com.hz.blog.mapper;

import com.hz.blog.model.entity.BlogEntity;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface BlogMapper {

    @Insert("insert into blogs values (null,#{title},#{content},#{author_id},#{author_username},#{author_realname},#{publish_time},#{is_anonymous},#{anonymous_name})")
    int addBlog(BlogEntity blogEntity);

    @Select("select * from blogs where id = #{id}")
    BlogEntity selectById(@Param("id") Integer id);

    @Delete("delete from blogs where id = #{id}")
    int delById(@Param("id") Integer id);

    @Update("update blogs set title = #{title}, content = #{content} where id = #{id}")
    int editBlog(@Param("id") Integer id, @Param("title") String title, @Param("content") String content);

    @Select("select * from blogs")
    List<BlogEntity> allBlogs();

    @Select("select * from blogs where author_id = #{userId}")
    List<BlogEntity> myBlogs(@Param("userId") Integer userId);

}
